<html>
    <head>
        <script language='javascript' src="popcalendar.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <TABLE width="80%" border="0" cellspacing="0">
            <TR>          
                <TD width="40%">
                    <BR>
                    <FORM action="index.php?task=IngresarFormacionDocente" name="form1" method="post">
                        <fieldset><legend>Docente</legend>
                            <TABLE border="1">                
                                <TR>
                                    <TD>DOCENTE</TD>
                                    <td>
                                        <select required = "si" name = "cedulaDocente" id = "sexo">
                                            <?php
                                            include("conectar.php");
                                            $link = Conectarse();
                                            $sql = "Select cedula, nombres || ' ' || apellidos as Nombres From docente;";
                                            $resConsulta = pg_exec($link, $sql);
                                            if (!$resConsulta) {
                                                die("Error in SQL query:" . pg_last_error());
                                            }
                                            while ($row = pg_fetch_array($resConsulta)) {
                                                echo "<option value=" . $row[0] . ">$row[1]</option>";
                                            }
                                            ?>      
                                        </select>
                                    </td>
                                </TR>
                                <TR>                   
                                    <TD>PUBLICACION</TD>
                                    <TD>
                                        <select required = "si" name = "codigoPublicacion" id = "cargo">
                                            <?php
                                            $sql1 = "Select codigopublicacion, descripcion From publicaciones;";
                                            $resConsulta1 = pg_exec($link, $sql1);
                                            while ($row = pg_fetch_array($resConsulta1)) {
                                                echo "<option value=" . $row[0] . ">$row[1]</option>";
                                            }
                                            ?>      
                                        </select>
                                    </TD>
                                </TR>

                                <TR>
                                    <TD>FECHA PUBLICACION</TD>
                                    <TD><input required = "si" name = "fecha" type = "text" id = "fecha" onClick = "popUpCalendar(this, form1.fecha, 'yyyy-mm-dd');" size = "12"></TD>
                                </TR>
                                <TR>
                                    <TD>DESCRIPCION</TD>
                                    <TD><INPUT required = "si" TYPE = "TextArea" NAME = "descripcion" SIZE = "20" MAXLENGTH = "30" 
                                               value=".$cargo."></TD>
                                </TR>                             
                            </table>
                        </fieldset>
                        <br>
                        <INPUT TYPE="submit" VALUE="Ingresar" name="ingreso" align="top">
                    </FORM>
                </TD>
            </TR>
        </TABLE>
        <?php
        if (isset($_POST['ingreso'])) {

            $cedulaDocente = $_POST["cedulaDocente"];
            $codigoPublicacion = $_POST["codigoPublicacion"];
            $fecha = $_POST["fecha"];
            $descripcion = $_POST["descripcion"];


            $business = new BusinessLogic();
            $op = $business->agregarPublicacionesDocente($cedulaDocente, $codigoPublicacion, $fecha, $descripcion);
            
//        echo 'Resultado de Op'.$op;
            if ($op != 0) {
                echo '<font color="green">Ingresado Correctamente</font>';
            } else {
                echo '<font color="red">Intente mas tarde</font>';
            }
        }
        ?>
    </body>
</html>
